#include "BankSimulation.cpp"

int main()
{
	int cash1 = 0, cash2 = 0, cash3 = 0, cash4 = 0;
	int array[4]; //holds time while a client is servicing
	int waitTime = 0;
	int len = 0;
	int maxLen = 0;
	int curLen = 0;
	int timeCashierFree = 0;

	for (int i = 0; i < 4; i++)
	{
		array[i] = 0;
	}

	BankSimulation b = BankSimulation();
	for (int i = 1; i <= 480; i++)
	{
		b.isClientInMinute(i);
		if (b.getIndexOfCashiers(i) != -1)
		{
			array[b.getIndexOfCashiers(i)] = (1 + (rand() % 480));
		}
		for (int j = 0; j < 4; j++)
		{
			if ((array[j] + b.getNumberFromIndex(j)) == i)
			{
				b.removeClient(j);
				array[j] = 0;
				switch (j)
				{
				case 0:
					cash1++;
					break;
				case 1:
					cash2++;
					break;
				case 2:
					cash3++;
					break;
				case 3:
					cash4++;
					break;
				default:
					cout << "Error" << endl;
					break;
				}


				if (b.isQueueNotEmpty()) 
				{
					b.fromQueueToCashier();
					array[j] = 1 + (rand() % 480);
				}
			}
		}
		if (b.isQueueNotEmpty())
		{
			waitTime++;
		}
		len += b.queueLen(i);
		curLen = b.queueLen(i);

		if (curLen > maxLen)
		{
			maxLen = curLen;
		}
		
		if (b.isCashierFree())
		{
			timeCashierFree++;
		}

	}

	cout << "Clients serviced: "<< b.getClientsServiced() << endl;
	cout << "Cashier 1: "<<cash1 << endl;
	cout << "Cashier 2: "<<cash2 << endl;
	cout << "Cashier 3: "<<cash3 << endl;
	cout << "Cashier 4: "<<cash4 << endl;
	cout << "Average time waiting: " << (double)(waitTime / b.getClientsServiced()) << endl;
	cout << "Average queue length: " << (double)len / 480 << endl;
	cout << "Maximal queue lenght: " << maxLen << endl;
	cout << "Percentage of time cashiers are free: " << ((double)timeCashierFree / 480) * 100 << "%" << endl;
}